import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../text/text_widget.dart';
import '../../common/object_util/object_util.dart';
import '../../common/app_text_style.dart';

/// 通用对话框组件
class GeneralDialogWidget extends StatefulWidget {
  GeneralDialogWidget(this.title, this.subTitle,
      {Key? key,
      this.leftText,
      this.rightText,
      this.leftTextStyle,
      this.rightTextStyle,
      this.leftBgColor,
      this.rightBgColor,
      this.leftActionEvent,
      this.rightActionEvent})
      : super(key: key);

  /// 标题
  String? title = "";
  /// 副标题
  String? subTitle = "";
  /// 左按钮文本
  String? leftText;
  /// 右按钮文本
  String? rightText;
  /// 左按钮文本样式
  TextStyle? leftTextStyle;
  /// 右按钮文本样式
  TextStyle? rightTextStyle;
  /// 左按钮背景颜色
  Color? leftBgColor;
  /// 右按钮背景颜色
  Color? rightBgColor;
  /// 左actionItem点击事件
  Function()? leftActionEvent;
  /// 右actionItem点击事件
  Function()? rightActionEvent;

  @override
  State<GeneralDialogWidget> createState() => GeneralDialogWidgetState();
}

class GeneralDialogWidgetState extends State<GeneralDialogWidget> {
  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Container(
          decoration: BoxDecoration(
            color: const Color(0xFFFFFFFF),
            borderRadius: BorderRadius.all(
              Radius.circular(18.w)
            ),
          ),
          padding: EdgeInsets.symmetric(horizontal: 16.w),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              SizedBox(height: 20.w),
              Row(
                children: [
                  Expanded(
                      child: SizedBox(
                    height: 28.w,
                    child: TextWidget(widget.title, TS_FF1D2129_20_W5,
                        textAlign: TextAlign.center),
                  )),
                ],
              ),
              SizedBox(height: 8.w),
              Row(
                children: [
                  Expanded(child: Container(
                    child: TextWidget(widget.subTitle, TS_D91D2129_14_W4,textAlign: TextAlign.center,
                        maxLines: 2),
                  ))
                ],
              ),
              SizedBox(height: 32.w),
              SizedBox(
                height: 48.w,
                width: ScreenUtil().screenWidth,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Expanded(
                        child: GestureDetector(
                      onTap: () {
                        // 左边按钮点击事件
                        Get.back();
                        if(ObjectUtil.isNotEmpty(widget.leftActionEvent)){
                          widget.leftActionEvent!();
                        }
                      },
                      child: Container(
                        alignment: Alignment.center,
                        height: 48.w,
                        margin: EdgeInsets.only(right: 8.w),
                        decoration: BoxDecoration(
                            borderRadius:
                            BorderRadius.all(Radius.circular(16.w)),
                            color: ObjectUtil.isNotEmpty(widget.leftBgColor) ? widget.leftBgColor : const Color(0xFFF7F8FA)),
                        child: TextWidget(ObjectUtil.isNotEmpty(widget.leftText)
                              ? widget.leftText!
                              : '取消',
                          ObjectUtil.isNotEmpty(
                              widget.leftTextStyle)
                              ? widget.leftTextStyle!
                              : TS_FF1D2129_16_W5,
                        ),
                      ),
                    )),
                    Expanded(
                        child: GestureDetector(
                      onTap: () {
                        // 右边按钮点击事件
                        Get.back();
                        if(ObjectUtil.isNotEmpty(widget.rightActionEvent)){
                          widget.rightActionEvent!();
                        }
                      },
                      child: Container(
                        alignment: Alignment.center,
                        height: 48.w,
                        margin: EdgeInsets.only(left: 8.w),
                        decoration: BoxDecoration(
                            borderRadius:
                                BorderRadius.all(Radius.circular(16.w)),
                            color: ObjectUtil.isNotEmpty(widget.rightBgColor)
                                ? widget.rightBgColor!
                                : const Color(0xFFFFF5F6)),
                        child: TextWidget(
                          ObjectUtil.isNotEmpty(widget.rightText)
                              ? widget.rightText
                              : '确定',
                           ObjectUtil.isNotEmpty(widget.rightTextStyle)
                              ? widget.rightTextStyle!
                              : TS_FFFF5773_16_W5,
                        ),
                      ),
                    )),
                  ],
                ),
              ),
              SizedBox(height: 24.w)
            ],
          )),
    );
  }
}
